﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Torch_WebApp.ViewModels.Function;

namespace Torch_WebApp.Controllers.WeChat
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FunctionController : ControllerBase
    {
        private IFunctionService _function;
        public FunctionController(IFunctionService function)
        {
            _function = function;
        }

        [HttpGet]
        public async Task<List<FunctionListViewModel>> GetWeChatList() 
        {
            var data = await _function.QueryAllFunctionAsync();
            if (data == null)
                return null;

            var List = data.Select(func => new FunctionListViewModel 
            {
                Id = func.Id,
                Title = func.Title,
                Img = func.Image,
                Link = func.Link
            }).ToList();
            
            return List;
        }
    }
}
